#include "levelloader.h"

LevelLoader::LevelLoader(std::string filePath) {
	int width = 0;
	int height = 0;
	std::ifstream fin;
	fin.open(filePath.c_str());

	std::string buffer;
	const char *temp;

	//Die ersten zwei Zeilen fuer die Dimensionen auslesen
	getline(fin, buffer, '\n');
	width = atoi(buffer.c_str());
	getline(fin, buffer, '\n');
	height = atoi(buffer.c_str());

	//Level anlegen (Konstruktor mit Dimensionen)
	this->levelData = new Level(width, height);

	//Einzelne Elemente setzen
	int y=0;
	while (fin.good()) {
		getline(fin, buffer, '\n');
		temp = buffer.c_str();

		for(int x=0; x<width; x++) {
			this->levelData->setTile(x, y, temp[x]);
		}

		y++;
	}

	fin.close();
}

LevelLoader::~LevelLoader(void) {
}

Level* LevelLoader::getLevelData(void) {
	return this->levelData;
}
